# coding: utf-8

import sys
import os
import shutil

msg = """
------------------------------/二\------------------------------
    欢迎进入 CentOS 环境初始化二级脚本
    二级脚本功能: 设置源
 
    请选择要执行的操作:
    
    1). 备份并清空 /etc/yum.repos.d/ 下面的所有源
    2). CentOS-Base.repo
    3). epel.repo
    4). mysql.repo
    5). nginx.repo
    6). webtatic.repo(php)
    7). remi.repo
    
   11). PyPi(Python源)
  r|R). 返回上级
------------------------------\二/------------------------------
"""


def source_set_pypi():
    """只设置root用户的"""
    print "--- 开始设置豆瓣源 ---"

    pypi_path_1 = '/root/.pip'
    if os.path.exists(pypi_path_1):
        print "%s 已存在, 跳过创建步骤! " % pypi_path_1
    else:
        os.mkdir('/root/.pip')

    print "开始拷贝配置文件..."
    script_cwd = os.getcwd()
    pypi_src_relative = r'source/pypi/pip_douban.conf'
    pypi_src = script_cwd + r'/' + pypi_src_relative
    # print pypi_src
    pypi_dest = r'%s/pip.conf' %pypi_path_1
    # print pypi_dest
    # shutil.copy(r'../source/pypi/pip_douban.conf', r'/root/.pip/pip.conf')
    shutil.copy(pypi_src, pypi_dest)
    print "结束拷贝配置文件! "

def source_set_base():
    pass


def source_set_epel():
    pass


# 设置源的函数
def source_do(input_2):
    # while True:
    pass


def source_main():
    while True:
        print msg
        input_2 = raw_input("请输入二级选项: ")
        # 判断输入: 开始执行任务或者进入三级菜单
        if input_2 == '1':
            pass
        elif input_2 == '2':
            pass
        elif input_2 == '3':
            pass
        elif input_2 == '4':
            pass
        elif input_2 == '5':
            pass
        elif input_2 == '6':
            pass
        elif input_2 == '7':
            pass
        elif input_2 == '11':
            source_set_pypi()
        elif input_2 in ('r', 'R'):
            print "开始返回上级"
            break
        else:
            print "输入错误, 请重新输入! "


